(ns fastmath.complex-test
  (:require [fastmath.complex :as c]
            [fastmath.core :as m]
            [fastmath.vector :as v]
            [clojure.test :refer [deftest is are]]))

;; expected reults verified with Wolfram Alpha and R

;; R code
;;
;; p<-c(-2.2, -0.8, 0.0, 0.8, 2.2)
;; d<-expand.grid(a=p,b=p)
;; f <- function(x,a) { atan(complex(real=x[1],imaginary=x[2])) }
;; res<-apply(d,1,f); print(cbind(d,Re(res), Im(res)), row.names=F)
;;

(deftest complex-operations
  (is (= (v/vec2 1.0 1.0) (c/complex 1.0 1.0)))
  (is (= (c/complex 1.0 1.0) (c/add c/I c/ONE)))
  (is (= (m/sqrt 2.0) (c/abs (c/complex 1.0 1.0))))
  (is (= (c/complex 1.0 1.0) (c/sub c/ONE c/I-)))
  (is (= -90.0 (m/degrees (c/arg c/I-))))
  (is (= (c/complex 0.0 -1.0) (c/conjugate c/I)))
  (is (= (c/complex 0.44 0.08) (c/div (c/complex 1 2) (c/complex 3 4))))
  (is (= (c/complex 0.12 -0.16) (c/reciprocal (c/complex 3 4))))
  (is (= (c/complex -5.0 10.0) (c/mult (c/complex 1 2) (c/complex 3 4))))
  (is (= (c/complex -1.0 2.0) (c/neg (c/complex 1.0 -2.0))))
  (is (= (c/complex -3.0 4.0) (c/sq (c/complex 1.0 2.0))))
  (is (= (c/complex 25.0 0.0) (c/sq (c/complex 5.0 0.0))))
  (is (= (c/complex (m/sqrt 2.0) 0.0) (c/sqrt (c/complex 2.0 0.0))))
  (is (c/delta-eq (c/complex 1.0 2.0) (c/sqrt (c/complex -3.0 4.0))))
  (is (c/delta-eq (c/complex 4.08 -2.94) (c/sqrt1z (c/complex 3 4)) 1.0e-3)))

(deftest complex-trig
  (is (c/delta-eq (c/complex 2.03 -3.05) (c/cos  (c/complex 1 2)) 1.0e-2))
  (is (c/delta-eq (c/complex 3.17 1.96)  (c/sin  (c/complex 1 2)) 1.0e-2))
  (is (c/delta-eq (c/complex -0.64 1.07) (c/cosh (c/complex 1 2)) 1.0e-2))
  (is (c/delta-eq (c/complex -0.49 1.4)  (c/sinh (c/complex 1 2)) 1.0e-2))
  (is (c/delta-eq (c/complex 0.03 1.01)  (c/tan  (c/complex 1 2)) 1.0e-2))
  (is (c/delta-eq (c/complex 1.17 -0.24) (c/tanh (c/complex 1 2)) 1.0e-2))
  (is (c/delta-eq (c/complex 0.15 0.23)  (c/sec  (c/complex 1 2)) 1.0e-2))
  (is (c/delta-eq (c/complex 0.23 -0.14) (c/csc  (c/complex 1 2)) 1.0e-2))
  (is (c/delta-eq (c/complex 1.14 -1.53) (c/acos (c/complex 1 2)) 1.0e-2))
  (is (c/delta-eq (c/complex 0.43 1.53)  (c/asin (c/complex 1 2)) 1.0e-2))
  (is (c/delta-eq (c/complex 1.34 0.4)   (c/atan (c/complex 1 2)) 1.0e-2)))

(deftest log-exp
  (is (c/delta-eq c/ZERO (c/add (c/exp (c/complex 0 m/PI)) c/ONE)))
  (is (c/delta-eq (c/complex -1.13 2.47) (c/exp (c/complex 1 2)) 1.0e-2))
  (is (= c/ONE (c/log (c/complex m/E 0.0))))
  (is (c/delta-eq (c/complex 0.8 1.11) (c/log (c/complex 1 2)) 1.0e-2))
  (is (c/delta-eq (c/complex -0.22 0.1) (c/pow (c/complex 1 2) (c/complex 1 2)) 1.0e-2))
  (are [a b ra rb] (c/delta-eq (c/complex ra rb)
                               (c/log (c/complex a b)))
    -2.2 -2.2 1.1350310 -2.3561945
    0.0 -2.2 0.7884574 -1.5707963
    2.2 -2.2 1.1350310 -0.7853982
    -2.2  0.0 0.7884574  3.1415927
    2.2  0.0 0.7884574  0.0000000
    -2.2  2.2 1.1350310  2.3561945
    0.0  2.2 0.7884574  1.5707963
    2.2  2.2 1.1350310  0.7853982))

(deftest power-branches
  (is (c/nan? (c/pow c/ZERO c/ZERO)))
  (is (c/zero? (c/pow c/ZERO (c/complex 1 1))))
  (is (c/inf? (c/pow (c/complex -0.0 0.0) c/ONE)))
  (is (= c/ONE (c/pow (c/complex 1 1) c/ZERO)))

  ;; real powers
  (is (c/delta-eq (c/complex 4.0 0.0) (c/pow c/TWO c/TWO)))
  (are [zr ra rb] (c/delta-eq (c/complex ra rb)
                              (c/pow (c/complex -2.0 0.0) (c/complex zr 0.0)) 1.0e-4)
    -3.3 -0.0597 0.0821
    -2.2 0.1760 -0.1279
    -1.1 -0.4437 0.1442
    -0.5 0.0 -0.7071
    0.5 0.0 1.4142
    1.1 -2.0386 -0.6624
    2.2 3.7173 2.7008
    3.3 -5.7892 -7.9681)

  (are [r i zi ra rb] (c/delta-eq (c/complex ra rb)
                                  (c/pow (c/complex r i) (c/complex 0.0 zi)) 1.0e-4)
    2.0 0.0 -3.3 -0.6568167 -0.7540503
    2.0 0.0 -2.2 0.0459 -0.9989
    2.0 0.0 -1.1 0.7231378 -0.6907038
    2.0 0.0 -0.5 0.9405421 -0.3396771
    2.0 0.0 0.5  0.9405421 0.3396771
    2.0 0.0 1.1 0.7231378 0.6907038
    2.0 0.0 2.2 0.0458564 0.998948
    2.0 0.0 3.3 -0.6568167 0.7540503

    -2.0 0.0 -3.3  -20887.4855 -23979.6184
    -2.0 0.0 -2.2  46.0287 -1002.6997
    -2.0 0.0 -1.1 22.91052 -21.88295
    -2.0 0.0 -0.5 4.524457 -1.634009
    -2.0 0.0 0.5 0.1955195 0.0706119
    -2.0 0.0 1.1 0.0228248 0.02180107
    -2.0 0.0 2.2 4.56849e-05 9.952104e-04

    -2.0 -0.0 3.3 -20887.4855 23979.6184
    -2.0 -0.0 2.2 46.0287 1002.6997
    -2.0 -0.0 1.1 22.91052 21.88295
    -2.0 -0.0 0.5 4.524457 1.634009
    -2.0 -0.0 -0.5 0.1955195 -0.0706119
    -2.0 -0.0 -1.1 0.0228248 -0.02180107
    -2.0 -0.0 -2.2 4.56849e-05 -9.952104e-04)

  (are [r i zi ra rb] (c/delta-eq (c/complex ra rb)
                                  (c/pow (c/complex r i) (c/complex 1.0 zi)) 1.0e-4)

    2.0 0.0 -3.3  -1.313633 -1.508101
    2.0 0.0 -2.2  0.091713 -1.997896
    2.0 0.0 -1.1 1.446276 -1.381408
    2.0 0.0 -0.5 1.881084 -0.679354
    2.0 0.0 0.5  1.881084 0.679354
    2.0 0.0 1.1 1.446276 1.381408
    2.0 0.0 2.2  0.091713 1.997896
    2.0 0.0 3.3  -1.313633 1.508101

    -2.0 0.0 -2.2 -92.0573 2005.3994
    -2.0 0.0 -1.1  -45.82105 43.7659
    -2.0 0.0 -0.5 -9.048913 3.268018
    -2.0 0.0 0.5 -0.391039 -0.1412239
    -2.0 0.0 1.1 -0.04564961 -0.04360215
    -2.0 0.0 2.2  -9.137e-05 -1.990421e-03

    -2.0 -0.0 2.2 -92.0573 -2005.3994
    -2.0 -0.0 1.1  -45.82105 -43.7659
    -2.0 -0.0 0.5 -9.048913 -3.268018
    -2.0 -0.0 -0.5 -0.391039 0.1412239
    -2.0 -0.0 -1.1 -0.04564961 0.04360215
    -2.0 -0.0 -2.2 -9.137e-05 1.990421e-03)

  (are [i zr ra rb] (c/delta-eq (c/complex ra rb)
                                (c/pow (c/complex 0.0 i) (c/complex zr 0.0)) 1.0e-4)
    -2.2 -2.2 -0.1678326 -0.0545321
    -2.2 2.2 -5.389348 1.751105
    2.2 2.2 -5.389348 -1.751105
    2.2 -2.2 -0.1678326 0.0545321)
  
  (are [i zi ra rb] (c/delta-eq (c/complex ra rb)
                                (c/pow (c/complex 0.0 i) (c/complex 0.0 zi)) 1.0e-4)
    -2.2 -2.2  -0.00514733 -0.03114103
    -2.2 2.2 -5.16666 31.25798
    2.2 2.2 -0.00514733 0.03114103
    2.2 -2.2  -5.16666 -31.25798)
  
  (are [i zr zi ra rb] (c/delta-eq (c/complex ra rb)
                                   (c/pow (c/complex 0.0 i) (c/complex zr zi)) 1.0e-4)
    -2.2 2.2 -2.2  0.082272 0.1588163
    -2.2 2.2 2.2 -26.8911 -177.5075
    2.2 2.2 2.2  0.082272 -0.1588163
    2.2 2.2 -2.2  -26.8911 177.5075
    -2.2 -2.2 -2.2  -0.000834296 0.005507175
    -2.2 -2.2 2.2 2.571699 -4.96436
    2.2 -2.2 2.2  -0.000834296 -0.005507175
    2.2 -2.2 -2.2  2.571699 4.96436)
  
  (are [r i zr ra rb] (c/delta-eq (c/complex ra rb)
                                  (c/pow (c/complex r i) (c/complex zr 0.0)) 1.0e-4)
    -2.2 2.2 -2.2 0.03737523 0.07335302 
    -2.2 2.2 2.2   5.51454 -10.8229
    2.2 2.2 2.2  -1.90018 11.99728 
    2.2 2.2 -2.2 -0.01287863 -0.08131245 
    -2.2 -2.2 -2.2  0.03737523 -0.07335302
    -2.2 -2.2 2.2  5.51454 10.8229
    2.2 -2.2 2.2  -1.90018 -11.99728
    2.2 -2.2 -2.2  -0.01287863 0.08131245)
  
  (are [r i zi ra rb] (c/delta-eq (c/complex ra rb)
                                  (c/pow (c/complex r i) (c/complex 0.0 zi)) 1.0e-4)
    -2.2 2.2 -2.2  -142.5533 -107.1431 
    -2.2 2.2 2.2 -0.004482655 0.003369165 
    2.2 2.2 2.2  -0.1420199 0.1067422
    2.2 2.2 -2.2  -4.49949 -3.381818
    -2.2 -2.2 -2.2 -0.004482655 -0.003369165
    -2.2 -2.2 2.2  -142.5533 107.1431
    2.2 -2.2 2.2  -4.49949 3.381818
    2.2 -2.2 -2.2  -0.1420199 -0.1067422)
  
  (are [r i ri zi ra rb] (c/delta-eq (c/complex ra rb)
                                     (c/pow (c/complex r i) (c/complex ri zi)) 1.0e-4)
    2.2 2.2 2.2 2.2     -1.010753 -1.906683          
    2.2 2.2 2.2 -2.2    49.12247 -47.55557           
    2.2 2.2 -2.2 2.2    0.01050849 0.01017329        
    2.2 2.2 -2.2 -2.2   -0.2170367 0.4094177         
    2.2 -2.2 2.2 2.2    49.12247 47.55557            
    2.2 -2.2 2.2 -2.2   -1.010753 1.906683           
    2.2 -2.2 -2.2 2.2   -0.2170367 -0.4094177        
    2.2 -2.2 -2.2 -2.2  0.01050849 -0.01017329       
    -2.2 2.2 2.2 2.2    0.01174435 0.06709475        
    -2.2 2.2 2.2 -2.2   -1945.716 951.995            
    -2.2 2.2 -2.2 2.2   -4.146787e-04 -2.028929e-04  
    -2.2 2.2 -2.2 -2.2  2.53131 -14.46121            
    -2.2 -2.2 2.2 2.2   -1945.716 -951.995           
    -2.2 -2.2 2.2 -2.2  0.01174435 -0.06709475       
    -2.2 -2.2 -2.2 2.2  2.53131 14.46121             
    -2.2 -2.2 -2.2 -2.2 -4.146787e-04 2.028929e-04))

(deftest trigonometric
  (are [a b ra rb] (c/delta-eq (c/complex ra rb)
                               (c/sin (c/complex a b)))
    -2.2 -2.2 -3.6931375 2.623011
    0.0 -2.2  0.0000000 -4.457105
    2.2 -2.2  3.6931375 2.623011
    -2.2  0.0 -0.8084964 0.000000
    0.0  0.0  0.0000000 0.000000
    2.2  0.0  0.8084964 0.000000
    -2.2  2.2 -3.6931375 -2.623011
    0.0  2.2  0.0000000 4.457105
    2.2  2.2  3.6931375 -2.623011)
  (are [a b ra rb] (c/delta-eq (c/complex ra rb)
                               (c/cos (c/complex a b)))
    -2.2 -2.2 -2.6882192 -3.603554
    0.0 -2.2  4.5679083  0.000000
    2.2 -2.2 -2.6882192  3.603554
    -2.2  0.0 -0.5885011  0.000000
    0.0  0.0  1.0000000  0.000000
    2.2  0.0 -0.5885011  0.000000
    -2.2  2.2 -2.6882192  3.603554
    0.0  2.2  4.5679083  0.000000
    2.2  2.2 -2.6882192 -3.603554)
  (are [a b ra rb] (c/delta-eq (c/complex ra rb)
                               (c/tan (c/complex a b)))
    -2.2 -2.2  0.02354038 -1.0072990
    0.0 -2.2  0.00000000 -0.9757431
    2.2 -2.2 -0.02354038 -1.0072990
    -2.2  0.0  1.37382306  0.0000000
    0.0  0.0  0.00000000  0.0000000
    2.2  0.0 -1.37382306  0.0000000
    -2.2  2.2  0.02354038  1.0072990
    0.0  2.2  0.00000000  0.9757431
    2.2  2.2 -0.02354038 1.0072990)
  (are [a b ra rb] (c/delta-eq (c/complex ra rb)
                               (c/sec (c/complex a b)))
    -2.2 -2.2 -0.1330004  0.1782868
    0.0 -2.2  0.2189186  0.0000000
    2.2 -2.2 -0.1330004 -0.1782868
    -2.2  0.0 -1.6992321  0.0000000
    0.0  0.0  1.0000000  0.0000000
    2.2  0.0 -1.6992321  0.0000000
    -2.2  2.2 -0.1330004 -0.1782868
    0.0  2.2  0.2189186  0.0000000
    2.2  2.2 -0.1330004  0.1782868)
  (is (= (c/complex ##Inf -0.0) (c/csc c/ZERO)))
  (are [a b ra rb] (c/delta-eq (c/complex ra rb)
                               (c/csc (c/complex a b)))
    -2.2 -2.2 -0.1799823 -0.1278305
    0.0 -2.2  0.0000000  0.2243609
    2.2 -2.2  0.1799823 -0.1278305
    -2.2  0.0 -1.2368639  0.0000000
    2.2  0.0  1.2368639  0.0000000
    -2.2  2.2 -0.1799823  0.1278305
    0.0  2.2  0.0000000 -0.2243609
    2.2  2.2  0.1799823  0.1278305)
  (is (= (c/complex ##Inf 0.0) (c/cot c/ZERO)))
  (are [a b ra rb] (c/delta-eq (c/complex ra rb)
                               (c/cot (c/complex a b)))
    -2.2 -2.2  0.0231878  0.992212
    0.0 -2.2  0.0000000  1.024860
    2.2 -2.2 -0.0231878  0.992212
    -2.2  0.0  0.7278958  0.000000
    2.2  0.0 -0.7278958  0.000000
    -2.2  2.2  0.0231878 -0.992212
    0.0  2.2  0.0000000 -1.024860
    2.2  2.2 -0.0231878 -0.992212))

(deftest hyperbolic
  (are [a b ra rb] (c/delta-eq (c/complex ra rb)
                               (c/sinh (c/complex a b)))
    -2.2 -2.2  2.623011 -3.6931375
    0.0 -2.2  0.000000 -0.8084964
    2.2 -2.2 -2.623011 -3.6931375
    -2.2  0.0 -4.457105  0.0000000
    0.0  0.0  0.000000  0.0000000
    2.2  0.0  4.457105  0.0000000
    -2.2  2.2  2.623011  3.6931375
    0.0  2.2  0.000000  0.8084964
    2.2  2.2 -2.623011  3.6931375)
  (are [a b ra rb] (c/delta-eq (c/complex ra rb)
                               (c/cosh (c/complex a b)))
    -2.2 -2.2 -2.6882192  3.603554
    0.0 -2.2 -0.5885011  0.000000
    2.2 -2.2 -2.6882192 -3.603554
    -2.2  0.0  4.5679083  0.000000
    0.0  0.0  1.0000000  0.000000
    2.2  0.0  4.5679083  0.000000
    -2.2  2.2 -2.6882192 -3.603554
    0.0  2.2 -0.5885011  0.000000
    2.2  2.2 -2.6882192  3.603554)
  (are [a b ra rb] (c/delta-eq (c/complex ra rb)
                               (c/tanh (c/complex a b)))
    -2.2 -2.2 -1.0072990  0.02354038
    0.0 -2.2  0.0000000  1.37382306
    2.2 -2.2  1.0072990  0.02354038
    -2.2  0.0 -0.9757431  0.00000000
    0.0  0.0  0.0000000  0.00000000
    2.2  0.0  0.9757431  0.00000000
    -2.2  2.2 -1.0072990 -0.02354038
    0.0  2.2  0.0000000 -1.37382306
    2.2  2.2  1.0072990 -0.02354038)
  (are [a b ra rb] (c/delta-eq (c/complex ra rb)
                               (c/sech (c/complex a b)))
    -2.2 -2.2 -0.1330004 -0.1782868
    0.0 -2.2 -1.6992321  0.0000000
    2.2 -2.2 -0.1330004  0.1782868
    -2.2  0.0  0.2189186  0.0000000
    0.0  0.0  1.0000000  0.0000000
    2.2  0.0  0.2189186  0.0000000
    -2.2  2.2 -0.1330004  0.1782868
    0.0  2.2 -1.6992321  0.0000000
    2.2  2.2 -0.1330004 -0.1782868)
  (is (= (c/complex ##Inf -0.0) (c/csch c/ZERO)))
  (are [a b ra rb] (c/delta-eq (c/complex ra rb)
                               (c/csch (c/complex a b)))
    -2.2 -2.2  0.1278305  0.1799823
    0.0 -2.2  0.0000000  1.2368639
    2.2 -2.2 -0.1278305  0.1799823
    -2.2  0.0 -0.2243609  0.0000000
    2.2  0.0  0.2243609  0.0000000
    -2.2  2.2  0.1278305 -0.1799823
    0.0  2.2  0.0000000 -1.2368639
    2.2  2.2 -0.1278305 -0.1799823)
  (is (= (c/complex ##Inf 0.0) (c/coth c/ZERO)))
  (are [a b ra rb] (c/delta-eq (c/complex ra rb)
                               (c/coth (c/complex a b)))
    -2.2 -2.2 -0.992212 -0.0231878
    0.0 -2.2  0.000000 -0.7278958
    2.2 -2.2  0.992212 -0.0231878
    -2.2  0.0 -1.024860  0.0000000
    2.2  0.0  1.024860  0.0000000
    -2.2  2.2 -0.992212  0.0231878
    0.0  2.2  0.000000  0.7278958
    2.2  2.2  0.992212  0.0231878))

;;

(deftest inverse-trigonometric
  (are [a b ra rb] (c/delta-eq (c/complex ra rb)
                               (c/asin (c/complex a b)))
    -2.2 -2.2 -0.7596289 -1.8291748
    -0.8 -2.2 -0.3222810 -1.5779921
    0.0 -2.2  0.0000000 -1.5296605
    0.8 -2.2  0.3222810 -1.5779921
    2.2 -2.2  0.7596289 -1.8291748
    -2.2 -0.8 -1.1893629 -1.5083878
    -0.8 -0.8 -0.6096435 -0.8641474
    0.0 -0.8  0.0000000 -0.7326683
    0.8 -0.8  0.6096435 -0.8641474
    2.2 -0.8  1.1893629 -1.5083878
    -2.2  0.0 -1.5707963  1.4254169
    -0.8  0.0 -0.9272952  0.0000000
    0.0  0.0  0.0000000  0.0000000
    0.8  0.0  0.9272952  0.0000000
    2.2  -0.0  1.5707963 -1.4254169 ;; -0.0
    -2.2  0.8 -1.1893629  1.5083878
    -0.8  0.8 -0.6096435  0.8641474
    0.0  0.8  0.0000000  0.7326683
    0.8  0.8  0.6096435  0.8641474
    2.2  0.8  1.1893629  1.5083878
    -2.2  2.2 -0.7596289  1.8291748
    -0.8  2.2 -0.3222810  1.5779921
    0.0  2.2  0.0000000  1.5296605
    0.8  2.2  0.3222810  1.5779921
    2.2  2.2  0.7596289  1.8291748)
  (are [a b ra rb] (c/delta-eq (c/complex ra rb)
                               (c/acos (c/complex a b)))
    -2.2 -2.2 2.3304252  1.8291748
    -0.8 -2.2 1.8930773  1.5779921
    0.0 -2.2 1.5707963  1.5296605
    0.8 -2.2 1.2485153  1.5779921
    2.2 -2.2 0.8111675  1.8291748
    -2.2 -0.8 2.7601592  1.5083878
    -0.8 -0.8 2.1804398  0.8641474
    0.0 -0.8 1.5707963  0.7326683
    0.8 -0.8 0.9611528  0.8641474
    2.2 -0.8 0.3814334  1.5083878
    -2.2  0.0 3.1415927 -1.4254169
    -0.8  0.0 2.4980915  0.0000000
    0.0  0.0 1.5707963  0.0000000
    0.8  0.0 0.6435011  0.0000000
    2.2  -0.0 0.0000000  1.4254169 ;; -0.0
    -2.2  0.8 2.7601592 -1.5083878
    -0.8  0.8 2.1804398 -0.8641474
    0.0  0.8 1.5707963 -0.7326683
    0.8  0.8 0.9611528 -0.8641474
    2.2  0.8 0.3814334 -1.5083878
    -2.2  2.2 2.3304252 -1.8291748
    -0.8  2.2 1.8930773 -1.5779921
    0.0  2.2 1.5707963 -1.5296605
    0.8  2.2 1.2485153 -1.5779921
    2.2  2.2 0.8111675 -1.8291748)
  (are [a b ra rb] (c/delta-eq (c/complex ra rb)
                               (c/atan (c/complex a b)))
    -2.2 -2.2 -1.3362152 -0.2189998
    -0.8 -2.2 -1.3992844 -0.4136396
    -0.0 -2.2 -1.5707963 -0.4904146
    0.8 -2.2  1.3992844 -0.4136396
    2.2 -2.2  1.3362152 -0.2189998
    -2.2 -0.8 -1.1826016 -0.1260617
    -0.8 -0.8 -0.8720210 -0.4353744
    0.0 -0.8  0.0000000 -1.0986123
    0.8 -0.8  0.8720210 -0.4353744
    2.2 -0.8  1.1826016 -0.1260617
    -2.2  0.0 -1.1441688  0.0000000
    -0.8  0.0 -0.6747409  0.0000000
    0.0  0.0  0.0000000  0.0000000
    0.8  0.0  0.6747409  0.0000000
    2.2  0.0  1.1441688  0.0000000
    -2.2  0.8 -1.1826016  0.1260617
    -0.8  0.8 -0.8720210  0.4353744
    0.0  0.8  0.0000000  1.0986123
    0.8  0.8  0.8720210  0.4353744
    2.2  0.8  1.1826016  0.1260617
    -2.2  2.2 -1.3362152  0.2189998
    -0.8  2.2 -1.3992844  0.4136396
    0.0  2.2  1.5707963  0.4904146
    0.8  2.2  1.3992844  0.4136396
    2.2  2.2  1.3362152  0.2189998)
  (is (= (c/complex ##Inf ##Inf) (c/asec c/ZERO)))
  (are [a b ra rb] (c/delta-eq (c/complex ra rb)
                               (c/asec (c/complex a b)))
    -2.2 -2.2 1.793986 -0.2309936
    -0.8 -2.2 1.706513 -0.3948458
    0.0 -2.2 1.570796 -0.4401912
    0.8 -2.2 1.435079 -0.3948458
    2.2 -2.2 1.347607 -0.2309936
    -2.2 -0.8 1.978474 -0.1583552
    -0.8 -0.8 2.101441 -0.6727468
    0.0 -0.8 1.570796 -1.0475930
    0.8 -0.8 1.040151 -0.6727468
    2.2 -0.8 1.163119 -0.1583552
    -2.2  0.0 2.042658  0.0000000
    -0.8  -0.0 3.141593 -0.6931472
    0.8  0.0 0.000000  0.6931472
    2.2  0.0 1.098934  0.0000000
    -2.2  0.8 1.978474  0.1583552
    -0.8  0.8 2.101441  0.6727468
    0.0  0.8 1.570796  1.0475930
    0.8  0.8 1.040151  0.6727468
    2.2  0.8 1.163119  0.1583552
    -2.2  2.2 1.793986  0.2309936
    -0.8  2.2 1.706513  0.3948458
    0.0  2.2 1.570796  0.4401912
    0.8  2.2 1.435079  0.3948458
    2.2  2.2 1.347607  0.2309936)
  (is (= (c/complex ##Inf ##Inf) (c/acsc c/ZERO)))
  (are [a b ra rb] (c/delta-eq (c/complex ra rb)
                               (c/acsc (c/complex a b)))
    -2.2 -2.2 -0.2231896  0.2309936
    -0.8 -2.2 -0.1357170  0.3948458
    0.0 -2.2  0.0000000  0.4401912
    0.8 -2.2  0.1357170  0.3948458
    2.2 -2.2  0.2231896  0.2309936
    -2.2 -0.8 -0.4076776  0.1583552
    -0.8 -0.8 -0.5306450  0.6727468
    0.0 -0.8  0.0000000  1.0475930
    0.8 -0.8  0.5306450  0.6727468
    2.2 -0.8  0.4076776  0.1583552
    -2.2  0.0 -0.4718618  0.0000000
    -0.8  -0.0 -1.5707963  0.6931472
    0.8  0.0  1.5707963 -0.6931472
    2.2  0.0  0.4718618  0.0000000
    -2.2  0.8 -0.4076776 -0.1583552
    -0.8  0.8 -0.5306450 -0.6727468
    0.0  0.8  0.0000000 -1.0475930
    0.8  0.8  0.5306450 -0.6727468
    2.2  0.8  0.4076776 -0.1583552
    -2.2  2.2 -0.2231896 -0.2309936
    -0.8  2.2 -0.1357170 -0.3948458
    0.0  2.2  0.0000000 -0.4401912
    0.8  2.2  0.1357170 -0.3948458
    2.2  2.2  0.2231896 -0.2309936)
  (are [a b ra rb] (c/delta-eq (c/complex ra rb)
                               (c/acot (c/complex a b)))
    -2.2 -2.2 -0.2345811  0.2189998
    -0.8 -2.2 -0.1715120  0.4136396
    0.0 -2.2  0.0000000  0.4904146
    0.8 -2.2  0.1715120  0.4136396
    2.2 -2.2  0.2345811  0.2189998
    -2.2 -0.8 -0.3881947  0.1260617
    -0.8 -0.8 -0.6987753  0.4353744
    0.0 -0.8  1.5707963  1.0986123
    0.8 -0.8  0.6987753  0.4353744
    2.2 -0.8  0.3881947  0.1260617
    -2.2  0.0 -0.4266275  0.0000000
    -0.8  0.0 -0.8960554  0.0000000
    0.0  0.0  1.5707963  0.0000000
    0.8  0.0  0.8960554  0.0000000
    2.2  0.0  0.4266275  0.0000000
    -2.2  0.8 -0.3881947 -0.1260617
    -0.8  0.8 -0.6987753 -0.4353744
    -0.0  0.8 -1.5707963 -1.0986123
    0.8  0.8  0.6987753 -0.4353744
    2.2  0.8  0.3881947 -0.1260617
    -2.2  2.2 -0.2345811 -0.2189998
    -0.8  2.2 -0.1715120 -0.4136396
    0.0  2.2  0.0000000 -0.4904146
    0.8  2.2  0.1715120 -0.4136396
    2.2  2.2  0.2345811 -0.2189998))

(deftest inverse-hyperbolic
  (are [a b ra rb] (c/delta-eq (c/complex ra rb)
                               (c/asinh (c/complex a b)))
    -2.2 -2.2 -1.8291748 -0.7596289
    -0.8 -2.2 -1.5083878 -1.1893629
    -0.0 -2.2 -1.4254169 -1.5707963
    0.8 -2.2  1.5083878 -1.1893629
    2.2 -2.2  1.8291748 -0.7596289
    -2.2 -0.8 -1.5779921 -0.3222810
    -0.8 -0.8 -0.8641474 -0.6096435
    0.0 -0.8  0.0000000 -0.9272952
    0.8 -0.8  0.8641474 -0.6096435
    2.2 -0.8  1.5779921 -0.3222810
    -2.2  0.0 -1.5296605  0.0000000
    -0.8  0.0 -0.7326683  0.0000000
    0.0  0.0  0.0000000  0.0000000
    0.8  0.0  0.7326683  0.0000000
    2.2  0.0  1.5296605  0.0000000
    -2.2  0.8 -1.5779921  0.3222810
    -0.8  0.8 -0.8641474  0.6096435
    0.0  0.8  0.0000000  0.9272952
    0.8  0.8  0.8641474  0.6096435
    2.2  0.8  1.5779921  0.3222810
    -2.2  2.2 -1.8291748  0.7596289
    -0.8  2.2 -1.5083878  1.1893629
    0.0  2.2  1.4254169  1.5707963
    0.8  2.2  1.5083878  1.1893629
    2.2  2.2  1.8291748  0.7596289)
  (are [a b ra rb] (c/delta-eq (c/complex ra rb)
                               (c/acosh (c/complex a b)))
    -2.2 -2.2 -1.8291748 2.3304252
    -0.8 -2.2 -1.5779921 1.8930773
    0.0 -2.2 -1.5296605 1.5707963
    0.8 -2.2 -1.5779921 1.2485153
    2.2 -2.2 -1.8291748 0.8111675
    -2.2 -0.8 -1.5083878 2.7601592
    -0.8 -0.8 -0.8641474 2.1804398
    0.0 -0.8 -0.7326683 1.5707963
    0.8 -0.8 -0.8641474 0.9611528
    2.2 -0.8 -1.5083878 0.3814334
    -2.2  0.0  1.4254169 3.1415927
    -0.8  0.0  0.0000000 2.4980915
    0.0  0.0  0.0000000 1.5707963
    0.8  0.0  0.0000000 0.6435011
    2.2  -0.0 -1.4254169 0.0000000
    -2.2  0.8  1.5083878 2.7601592
    -0.8  0.8  0.8641474 2.1804398
    0.0  0.8  0.7326683 1.5707963
    0.8  0.8  0.8641474 0.9611528
    2.2  0.8  1.5083878 0.3814334
    -2.2  2.2  1.8291748 2.3304252
    -0.8  2.2  1.5779921 1.8930773
    0.0  2.2  1.5296605 1.5707963
    0.8  2.2  1.5779921 1.2485153
    2.2  2.2  1.8291748 0.8111675)
  (are [a b ra rb] (c/delta-eq (c/complex ra rb)
                               (c/atanh (c/complex a b)))
    -2.2 -2.2 -0.2189998 -1.3362152
    -0.8 -2.2 -0.1260617 -1.1826016
    0.0 -2.2  0.0000000 -1.1441688
    0.8 -2.2  0.1260617 -1.1826016
    2.2 -2.2  0.2189998 -1.3362152
    -2.2 -0.8 -0.4136396 -1.3992844
    -0.8 -0.8 -0.4353744 -0.8720210
    0.0 -0.8  0.0000000 -0.6747409
    0.8 -0.8  0.4353744 -0.8720210
    2.2 -0.8  0.4136396 -1.3992844
    -2.2  0.0 -0.4904146  1.5707963
    -0.8  0.0 -1.0986123  0.0000000
    0.0  0.0  0.0000000  0.0000000
    0.8  0.0  1.0986123  0.0000000
    2.2  -0.0  0.4904146 -1.5707963
    -2.2  0.8 -0.4136396  1.3992844
    -0.8  0.8 -0.4353744  0.8720210
    0.0  0.8  0.0000000  0.6747409
    0.8  0.8  0.4353744  0.8720210
    2.2  0.8  0.4136396  1.3992844
    -2.2  2.2 -0.2189998  1.3362152
    -0.8  2.2 -0.1260617  1.1826016
    0.0  2.2  0.0000000  1.1441688
    0.8  2.2  0.1260617  1.1826016
    2.2  2.2  0.2189998  1.3362152)
  (are [a b ra rb] (c/delta-eq (c/complex ra rb)
                               (c/asech (c/complex a b)))
    -2.2 -2.2  0.2309936 1.793986
    -0.8 -2.2  0.3948458 1.706513
    0.0 -2.2  0.4401912 1.570796
    0.8 -2.2  0.3948458 1.435079
    2.2 -2.2  0.2309936 1.347607
    -2.2 -0.8  0.1583552 1.978474
    -0.8 -0.8  0.6727468 2.101441
    0.0 -0.8  1.0475930 1.570796
    0.8 -0.8  0.6727468 1.040151
    2.2 -0.8  0.1583552 1.163119
    -2.2  0.0  0.0000000 2.042658
    -0.8  -0.0  0.6931472 3.141593
    0.8  0.0 -0.6931472 0.000000
    2.2  0.0  0.0000000 1.098934
    -2.2  0.8 -0.1583552 1.978474
    -0.8  0.8 -0.6727468 2.101441
    0.0  0.8 -1.0475930 1.570796
    0.8  0.8 -0.6727468 1.040151
    2.2  0.8 -0.1583552 1.163119
    -2.2  2.2 -0.2309936 1.793986
    -0.8  2.2 -0.3948458 1.706513
    0.0  2.2 -0.4401912 1.570796
    0.8  2.2 -0.3948458 1.435079
    2.2  2.2 -0.2309936 1.347607)
  (are [a b ra rb] (c/delta-eq (c/complex ra rb)
                               (c/acsch (c/complex a b)))
    -2.2 -2.2 -0.2309936  0.2231896
    -0.8 -2.2 -0.1583552  0.4076776
    0.0 -2.2  0.0000000  0.4718618
    0.8 -2.2  0.1583552  0.4076776
    2.2 -2.2  0.2309936  0.2231896
    -2.2 -0.8 -0.3948458  0.1357170
    -0.8 -0.8 -0.6727468  0.5306450
    0.0 -0.8  0.6931472  1.5707963
    0.8 -0.8  0.6727468  0.5306450
    2.2 -0.8  0.3948458  0.1357170
    -2.2  0.0 -0.4401912  0.0000000
    -0.8  0.0 -1.0475930  0.0000000
    0.8  0.0  1.0475930  0.0000000
    2.2  0.0  0.4401912  0.0000000
    -2.2  0.8 -0.3948458 -0.1357170
    -0.8  0.8 -0.6727468 -0.5306450
    -0.0  0.8 -0.6931472 -1.5707963
    0.8  0.8  0.6727468 -0.5306450
    2.2  0.8  0.3948458 -0.1357170
    -2.2  2.2 -0.2309936 -0.2231896
    -0.8  2.2 -0.1583552 -0.4076776
    0.0  2.2  0.0000000 -0.4718618
    0.8  2.2  0.1583552 -0.4076776
    2.2  2.2  0.2309936 -0.2231896)
  (are [a b ra rb] (c/delta-eq (c/complex ra rb)
                               (c/acoth (c/complex a b)))
    -2.2 -2.2 -0.2189998  0.2345811
    -0.8 -2.2 -0.1260617  0.3881947
    0.0 -2.2  0.0000000  0.4266275
    0.8 -2.2  0.1260617  0.3881947
    2.2 -2.2  0.2189998  0.2345811
    -2.2 -0.8 -0.4136396  0.1715120
    -0.8 -0.8 -0.4353744  0.6987753
    0.0 -0.8  0.0000000  0.8960554
    0.8 -0.8  0.4353744  0.6987753
    2.2 -0.8  0.4136396  0.1715120
    -2.2  0.0 -0.4904146  0.0000000
    -0.8  -0.0 -1.0986123  1.5707963
    0.8  0.0  1.0986123 -1.5707963
    2.2  0.0  0.4904146  0.0000000
    -2.2  0.8 -0.4136396 -0.1715120
    -0.8  0.8 -0.4353744 -0.6987753
    0.0  0.8  0.0000000 -0.8960554
    0.8  0.8  0.4353744 -0.6987753
    2.2  0.8  0.4136396 -0.1715120
    -2.2  2.2 -0.2189998 -0.2345811
    -0.8  2.2 -0.1260617 -0.3881947
    0.0  2.2  0.0000000 -0.4266275
    0.8  2.2  0.1260617 -0.3881947
    2.2  2.2  0.2189998 -0.2345811))
